package cn.doitedu.zk.api;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;

import java.io.IOException;

/**
 * @date: 2019/7/8
 * @site: www.doitedu.cn
 * @author: hunter.d 涛哥
 * @qq: 657270652
 * @description:  zookeeper客户端连接测试
 */
public class ZKEnvTest {
    public static void main(String[] args) throws IOException, KeeperException, InterruptedException {

        // 构造一个zk的客户端
        ZooKeeper zk = new ZooKeeper("spark01:2181,spark02:2181,spark03:2181", 2000, null);

        // 测试是否能够正常操作zookeeper服务
        Stat stat = zk.exists("/xxoo", false);

        if(stat==null){
            System.out.println("/xxoo 不存在");
        }else{
            System.out.println("/xxoo 存在");
        }
        zk.close();
    }
}
